package com.jiazhong.Servlet;

import com.jiazhong.Model.Goods;
import com.jiazhong.Service.GoodsService;
import com.jiazhong.Service.Impl.GoodsServiceImpl;
import com.jiazhong.utils.Utils;

import javax.rmi.CORBA.Util;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/goods/updateGoods.do")
public class UpdateGoodsServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            request.setCharacterEncoding("utf-8");
//            int goods_id=Integer.parseInt(request.getParameter("goods_id"));
//            String goods_name=request.getParameter("goods_name");
//            double goods_price= Double.parseDouble(request.getParameter("goods_price"));
//            String goods_str=request.getParameter("goods_time");
//            Date goods_time=new SimpleDateFormat("yyyy-MM-dd").parse(goods_str);
//            Goods goods=new Goods(goods_id,goods_name,goods_price,goods_time);

            Goods goods=Utils.encapsulationRequestToBean(Goods.class,request);

            GoodsService goodsService=new GoodsServiceImpl();
            goodsService.updateGoods(goods);
            response.sendRedirect("/goods/queryGoods.do");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }


}
